package com.rt.gptnext.common.utils.io;

import cn.hutool.core.io.IoUtil;

import java.io.IOException;
import java.io.OutputStream;

/**
 * 多输出流对象
 *
 * @author gaoyiyang
 */
public class MultiOutputStream extends OutputStream {

    private final OutputStream[] outs;

    public MultiOutputStream(OutputStream... outs) {
        this.outs = outs;
    }

    @Override
    public void write(int b) throws IOException {
        for (OutputStream out : outs) {
            out.write(b);
        }
    }

    @Override
    public void flush() throws IOException {
        for (OutputStream out : outs) {
            IoUtil.flush(out);
        }
    }

    @Override
    public void close() throws IOException {
        for (OutputStream out : outs) {
            IoUtil.close(out);
        }
    }
}
